<?php
//判断是否已经登录
if(isset($_SESSION['slast_key'])) 
{
	unset($_SESSION['slast_key']);
}
include_once(BASE_PATH.DS.'api'.DS.'sina'.DS.'config.php');
include_once(BASE_PATH.DS.'api'.DS.'sina'.DS.'saetv2.ex.class.php' );
$o = new SaeTOAuthV2( WB_AKEY , WB_SKEY);
///////////code需要传递////////////
if (isset($_REQUEST['code'])) {
	$keys = array();
	$keys['code'] = $_REQUEST['code'];
	$keys['redirect_uri'] = WB_CALLBACK_URL;
	try {
		$token = $o->getAccessToken( 'code', $keys ) ;
	} catch (OAuthException $e) {
	}
}
if ($token) {
	//获取新浪微博账号信息
	require_once (BASE_PATH.DS.'api'.DS.'sina'.DS.'saetv2.ex.class.php');
	$c = new SaeTClientV2(WB_AKEY,WB_SKEY ,$token['access_token']);
	$userInfo = $c->show_user_by_id($token['uid']);//根据ID获取用户等基本信息
	if($userInfo){
		//授权用户信息
		$_SESSION['oauth_info']=array(
			'oauth_form'=>'sina',//授权来源
			'oauth_info'=>$userInfo,//授权信息
			'oauth_user_name'=>$userInfo['screen_name'],//授权平台用户名或昵称
			'oauth_user_avatar'=>$userInfo['profile_image_url'],//授权平台用户头像
			'openid'=>$token['uid'],//用户唯一标识
			'unionid'=>'',//开放平台应用唯一id，用于微信
		);
		//转到注册登录页面
		@header('location: '.SHOP_SITE_URL.'/index.php?act=login');
	}else{
		die('授权失败。');
	}
} else { echo "授权失败。"; }


